<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>摩旅圈App后台管理</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.default.css" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/prettify/prettify.css" type="text/css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/prettify/prettify.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-migrate-1.1.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.flot.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.flot.resize.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.cookie.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/custom.js"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/excanvas.min.js"></script><![endif]-->
</head>

<body>

<div class="mainwrapper">
	
    <!-- START OF LEFT PANEL -->
    <div class="leftpanel">
    	
        <div class="logopanel">
        	<h1><a href="${pageContext.request.contextPath}/index.jsp">摩旅圈 <span>v1.0</span></a></h1>
        </div><!--logopanel-->
        
        <div class="leftmenu">
				<ul class="nav nav-tabs nav-stacked">
					<li class="nav-header">主功能</li>
					<li class="dropdown"><a
						href="${pageContext.request.contextPath}/index.jsp"><span
							class="icon-pencil"></span> 发帖</a>
						<ul>
							<li><a
								href="${pageContext.request.contextPath}/post_find.jsp">发现贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/post_picture.jsp">图文贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/post_team.jsp">组队贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/post_trade.jsp">交易贴</a></li>
						</ul></li>
					<li class="dropdown"><a
						href="${pageContext.request.contextPath}/post_elite.jsp"><span
							class=" icon-edit"></span> 帖子管理</a>
						<ul>
							<li><a
								href="${pageContext.request.contextPath}/posts/getAllPostsDiscover">发现贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/posts/getPostsPic">图文贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/posts/getPostsFriend">组队贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/posts/getPostsTrade">交易贴</a></li>
						</ul>
					</li>
					<li class="dropdown"><a
						href="${pageContext.request.contextPath}/media.jsp"><span
							class="icon-picture"></span> App图片</a>
						<ul>
							<li><a
								href="${pageContext.request.contextPath}/welcome.jsp">欢迎页配置</a></li>
							<li><a href="${pageContext.request.contextPath}/start_pic.jsp">首页轮播图</a></li>
						</ul></li>
					<li><a href="${pageContext.request.contextPath}/user/userList"><span
							class="iconsweets-male"></span> 用户管理</a></li>

				</ul>
			</div>
			<!--leftmenu-->
        
    </div><!--mainleft-->
    <!-- END OF LEFT PANEL -->
    
    <!-- START OF RIGHT PANEL -->
    <div class="rightpanel">
    	<div class="headerpanel">
        	<a href="" class="showmenu"></a>
            
            <div class="headerright">
    			<div class="dropdown userinfo">
                    <a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="/page.jsp">Hi, ${sessionScope.username}&nbsp;! <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <%-- <li><a href="${pageContext.request.contextPath}/index.jsp"><span
									class="icon-edit"></span> 修改密码</a></li> 
							<li class="divider"></li>--%>
							<li><a href="${pageContext.request.contextPath}/login.jsp"><span
									class="icon-off"></span> 退出</a></li>
                    </ul>
                </div><!--dropdown-->
    		
            </div><!--headerright-->
            
    	</div><!--headerpanel-->
        <div class="breadcrumbwidget">
        	<!-- <ul class="skins">
                <li><a href="default" class="skin-color default"></a></li>
                <li><a href="orange" class="skin-color orange"></a></li>
                <li><a href="dark" class="skin-color dark"></a></li>
                <li>&nbsp;</li>
                <li class="fixed"><a href="" class="skin-layout fixed"></a></li>
                <li class="wide"><a href="" class="skin-layout wide"></a></li>
            </ul>skins -->
        	<ul class="breadcrumb">
                <li><a href="${pageContext.request.contextPath}/index.jsp">Home</a> <span class="divider">/</span></li>
                <li class="active">发现贴修改</li>
            </ul>
        </div><!--breadcrumbwidget-->
        
        <div class="maincontent">
        	<div class="contentinner">
    
                <div class="widgetcontent">
                	<form class="stdform" action="${pageContext.request.contextPath}/posts/updatePosts" enctype="multipart/form-data" method="post">
                        <p>
                        	<input type="hidden" name="postsType" value="4">
                        	<input id="postsId" name="postsId" type="hidden" value="${param.id}"/>
                        </p>
                        <p>
                        	<label>帖子主题</label>
                            <span class="field"><input type="text" id="subject" name="subject" class="input-xlarge" placeholder="请输入帖子主题" value=""/></span>
                        </p>
                        
                        <p>
                        	<label>帖子内容</label>
                            <span class="field"><textarea cols="80" rows="5" id="content" name="content" class="span5" placeholder="请输入帖子内容"></textarea></span> 
                        </p>
						
						<p>
                            <label>帖子图片</label>
                            <span class="field">
                            </span>
                        </p>
                        <div class="field">
							<ul id="picul" class="listfile">
	                            <!-- <li>
                            		<img name= "pic" src="http:\/\/7xt0fg.com2.z0.glb.clouddn.com\/651352441.jpg-motostyle320" alt="" width="170px" height="170px"/>
	                            	<span class="filename">
	                            		Movie1.avi
	                            		<span class="iconsweets-trashcan" title="删除" style="float:right;" onclick="del(this);"></span>
	                            	</span>
	                            </li> -->
	                        </ul>
                        </div>
                        <p>
                            <span class="field">
                            	<input type="file" class="uniform-file" name="post_pic" /><input type="text" name="picdesc" placeholder="图片简单说明" />
                            </span>
                        </p>
						<p>
                            <span class="field">
                            </span>
                        </p>

						<span class="field">
							<div id="add"> 
 
							</div> 
						</span>

						<p>
							<span class="field">
							<span class="icon-plus"></span>
							<input name="" type="button" value="添加帖子图片" onClick="AddElement('file')" /> 
                            </span>
							
						</p>

                        <p class="stdformbutton">
                            <button class="btn btn-danger">修改</button>
                            <a href="${pageContext.request.contextPath}/posts/getAllPostsDiscover" class="btn btn-info">返回</a>
                        </p>
  
                    </form>  
                </div>
        </div>
    </div>
    
</div>
<script>  
function AddElement(mytype){  
var mytype,TemO=document.getElementById("add");  
var newInput = document.createElement("input");   
newInput.type=mytype;   
newInput.name="post_pic";  
TemO.appendChild(newInput);  

var newInput2 = document.createElement("input");   
newInput2.type="text";   
newInput2.name="picdesc"; 
newInput2.placeholder="图片简单说明";
TemO.appendChild(newInput2);

var newline2= document.createElement("br");  
TemO.appendChild(newline2);  

var newline3= document.createElement("br");  
TemO.appendChild(newline3); 
} 
var jq = jQuery.noConflict();
var apiUrl = "${pageContext.request.contextPath}";
var postsId = "${param.id}";
jq(document).ready(function(){
	jq.ajax({
		url : apiUrl + "/posts/get",
		type : 'GET',
		data : {
			'postsId' : postsId,
		},
		dataType : 'json',
		success : function(result) {
			var posts = result;
			for(var key in posts){
				jq("#subject").attr("value",posts[key].postsSubject);
				jq("#content").val(posts[key].postsContent);
				var pic = posts[key].postsPics.substring(8);
				pic = pic.substring(0,pic.length-2);
				var url = pic.split(',');
				for(var i in url){
					var l = url.length-1;
					if(url==null||url==''){
						
					}else if(i==0){
				    	//第一张图片路径
				    	//name为图片名称，格式：896632.jpeg
				    	var first = url[0];
				    	/* var index1=first.indexOf(".jpeg");
				    	var index2=index1-6;
				    	var name = first.substring(index1,index2); */
						jq("#picul").append(" <li><img width='170px' height='170px' name='pic' src= "+first+"/><span class='filename'><span class='iconsweets-trashcan' title='删除' style='float:right' onclick='del(this,"+first+","+i+")'></span></span></li>");
				    	

					}else if(i==l){
						//最后一张图片路径
						var end = url[l];
						jq("#picul").append(" <li><img width='170px' height='170px' name='pic' src= "+end+"/><span class='filename'><span class='iconsweets-trashcan' title='删除' style='float:right' onclick='del(this,"+end+","+i+")'></span></span></li>");
					}else{
						//中间图片路径
						var others = url[i];
						jq("#picul").append(" <li><img width='170px' height='170px' name='pic' src= "+others+"/><span class='filename'><span class='iconsweets-trashcan' title='删除' style='float:right' onclick='del(this,"+others+","+i+")'></span></span></li>");
					}
				}
			}
		},
		error : function() {
			alert("错误！");

		}
	}); 
});
function del(obj,url,i){
	var dom = jq(obj).parent().parent();
	var sure = confirm('确定删除吗？', function() {
	}, null);
	if (sure) {
		jq.ajax({
			url : apiUrl + "/posts/deleteImg",
			type : 'GET',
			data : {
				'imgName' : url,
				'postsId' :postsId,
				'index' : i,
			},
			dataType : 'json',
			success : function(result) {

				if (result = true) {
					/* location.href = apiUrl
							+ "/posts/getAllPostsDiscover"; */
					dom.remove();
				} else {

				}
			},
			error : function() {
				alert("删除失败！");
			}
		})
	}
}
</script>
</body>
</html>
